package com.ruoyi.web.controller.his;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.his.domain.HisTeamGroup;
import com.ruoyi.his.service.IHisTeamGroupService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班组信息Controller
 * 
 * @author tsenlem
 * @date 2023-11-01
 */
@Controller
@RequestMapping("/his/team")
public class HisTeamGroupController extends BaseController
{
    private String prefix = "his/team";

    @Autowired
    private IHisTeamGroupService hisTeamGroupService;

    @RequiresPermissions("his:team:view")
    @GetMapping()
    public String team()
    {
        return prefix + "/team";
    }

    /**
     * 查询班组信息列表
     */
    @RequiresPermissions("his:team:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HisTeamGroup hisTeamGroup)
    {
        startPage();
        List<HisTeamGroup> list = hisTeamGroupService.selectHisTeamGroupList(hisTeamGroup);
        return getDataTable(list);
    }

    /**
     * 导出班组信息列表
     */
    @RequiresPermissions("his:team:export")
    @Log(title = "班组信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HisTeamGroup hisTeamGroup)
    {
        List<HisTeamGroup> list = hisTeamGroupService.selectHisTeamGroupList(hisTeamGroup);
        ExcelUtil<HisTeamGroup> util = new ExcelUtil<HisTeamGroup>(HisTeamGroup.class);
        return util.exportExcel(list, "班组信息数据");
    }

    /**
     * 新增班组信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存班组信息
     */
    @RequiresPermissions("his:team:add")
    @Log(title = "班组信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HisTeamGroup hisTeamGroup)
    {
        hisTeamGroup.setCreateBy(getLoginName());
        return toAjax(hisTeamGroupService.insertHisTeamGroup(hisTeamGroup));
    }

    /**
     * 修改班组信息
     */
    @RequiresPermissions("his:team:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HisTeamGroup hisTeamGroup = hisTeamGroupService.selectHisTeamGroupById(id);
        mmap.put("hisTeamGroup", hisTeamGroup);
        return prefix + "/edit";
    }

    /**
     * 修改保存班组信息
     */
    @RequiresPermissions("his:team:edit")
    @Log(title = "班组信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HisTeamGroup hisTeamGroup)
    {
        return toAjax(hisTeamGroupService.updateHisTeamGroup(hisTeamGroup));
    }

    /**
     * 删除班组信息
     */
    @RequiresPermissions("his:team:remove")
    @Log(title = "班组信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hisTeamGroupService.deleteHisTeamGroupByIds(ids));
    }

    /**
     * 状态修改
     */
    @RequiresPermissions("his:section:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(HisTeamGroup teamGroup) {
        teamGroup.setUpdateBy(getLoginName());
        teamGroup.setUpdateTime(new Date());
        return toAjax(hisTeamGroupService.changeStatus(teamGroup));
    }
}
